/**
 * @Title: UserServiceIml.java
 * @Description:
 * @author zsw
 * <p>
 * Copyright(C) 2018-2019    NPlus
 * Company:   无锡核心信息科技有限公司
 * @version V2.0.0
 * @Date: 13:29 2019/10/17
 * <p>
 * 修改历史:
 * Date                 Author        Version        Description
 * -----------------------------------------------------------------------------------
 * 13:29 2019/10/17       zsw        2.0.0           初始化版本
 */
package com.example.springjpa.service.impl;

import com.example.springjpa.dao.UserDao;
import com.example.springjpa.model.User;
import com.example.springjpa.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Override
    public void add(User user) {
        userDao.save(user);
    }

    @Override
    @Cacheable(cacheNames = "User", key = "#id")
    public User getUser(Long id) {
        Optional<User> user = userDao.findById(id);
        return user.get();
    }
}
